package com.situ.root.goodsA.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.root.goodsA.model.GoodsAModel;
import com.situ.root.goodsA.service.IGoodsAService;
import com.situ.root.user.model.UserModel;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("/goodsA")
public class GoodsAController {

	@Autowired
	private IGoodsAService goodsAservice;
	
	
	@RequestMapping(value = "/add",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String add(GoodsAModel model) {
		int res = goodsAservice.insert(model);
		System.out.println("res="+res);
		return "1";
	}
	
	@RequestMapping(value = "/list" ,produces = {"application/json;charset=UTF-8"} ,method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public List<GoodsAModel> list(GoodsAModel goodsAModel) {
		List<GoodsAModel> res = goodsAservice.selectList(goodsAModel);
		res = JSONArray.fromObject(res);
		System.out.println("res=" + res);
		return res;
	}
	
	@RequestMapping(value = "/del",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String del(GoodsAModel model) {
		int res = goodsAservice.delete(model);
		System.out.println("res=" + res);
		return "1";
	}
	
	@RequestMapping(value = "/get",produces = {"application/json;charset=UTF-8"} ,method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public List<GoodsAModel> get(GoodsAModel model) {
		List<GoodsAModel> res = goodsAservice.selectList(model);
		res = JSONArray.fromObject(res);
		System.out.println("res=" + res);
		return res;
	}
	
	@RequestMapping(value = "/test",produces = {"application/json;charset=UTF-8"} ,method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public List<GoodsAModel> test(GoodsAModel model) {
		List<GoodsAModel> res = goodsAservice.selectTest(model);
		res = JSONArray.fromObject(res);
		System.out.println("res=" + res);
		return res;
	}
	
	@RequestMapping(value = "/upd",produces = {"application/json;charset=UTF-8"},method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String upd(GoodsAModel model) {
		int res = goodsAservice.update(model);
		System.out.println("res="+ res);
		return "1";
	}
	
	@RequestMapping(value = "/page",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> page(GoodsAModel model) {
		model.setPageOn(true);
		Map<String,Object> map = new HashMap<>();
		map.put("data", goodsAservice.selectList(model));
        map.put("count", goodsAservice.selectCount(model));
		map = net.sf.json.JSONObject.fromObject(map);
		System.out.println("map=" + map);
		return map;
	}
}
